/// 设备类型枚举
enum DeviceType {
  /// 温度传感器
  temperatureSensor,
  
  /// 湿度传感器
  humiditySensor,
  
  /// 光照传感器
  lightSensor,
  
  /// 二氧化碳传感器
  co2Sensor,
  
  /// 空气质量传感器
  airQualitySensor,
  
  /// 水分传感器
  moistureSensor,
  
  /// 运动传感器
  motionSensor,
  
  /// 门禁传感器
  doorSensor,
  
  /// 窗户传感器
  windowSensor,
  
  /// 烟雾传感器
  smokeSensor,
  
  /// 智能灯泡
  smartLight,
  
  /// 智能插座
  smartPlug,
  
  /// 智能开关
  smartSwitch,
  
  /// 智能窗帘
  smartCurtain,
  
  /// 智能门锁
  smartLock,
  
  /// 智能扬声器
  smartSpeaker,
  
  /// 智能摄像头
  camera,
  
  /// 智能网关
  gateway,
  
  /// 控制器
  controller,
  
  /// 其他类型
  other,
  
  /// 未知类型
  unknown,
}

/// 设备类型扩展
extension DeviceTypeExtension on DeviceType {
  /// 将字符串转换为设备类型
  static DeviceType fromString(String value) {
    return DeviceType.values.firstWhere(
      (type) => type.toString().split('.').last.toLowerCase() == value.toLowerCase(),
      orElse: () => DeviceType.unknown,
    );
  }
  
  /// 获取设备类型的显示名称
  String get displayName {
    switch (this) {
      case DeviceType.temperatureSensor: return '温度传感器';
      case DeviceType.humiditySensor: return '湿度传感器';
      case DeviceType.lightSensor: return '光照传感器';
      case DeviceType.co2Sensor: return '二氧化碳传感器';
      case DeviceType.airQualitySensor: return '空气质量传感器';
      case DeviceType.moistureSensor: return '水分传感器';
      case DeviceType.motionSensor: return '运动传感器';
      case DeviceType.doorSensor: return '门禁传感器';
      case DeviceType.windowSensor: return '窗户传感器';
      case DeviceType.smokeSensor: return '烟雾传感器';
      case DeviceType.smartLight: return '智能灯泡';
      case DeviceType.smartPlug: return '智能插座';
      case DeviceType.smartSwitch: return '智能开关';
      case DeviceType.smartCurtain: return '智能窗帘';
      case DeviceType.smartLock: return '智能门锁';
      case DeviceType.smartSpeaker: return '智能扬声器';
      case DeviceType.camera: return '智能摄像头';
      case DeviceType.gateway: return '智能网关';
      case DeviceType.controller: return '控制器';
      case DeviceType.other: return '其他设备';
      case DeviceType.unknown: return '未知设备';
    }
  }
  
  /// 获取设备类型的图标名称
  String get iconName {
    switch (this) {
      case DeviceType.temperatureSensor: return 'temperature';
      case DeviceType.humiditySensor: return 'humidity';
      case DeviceType.lightSensor: return 'light_sensor';
      case DeviceType.co2Sensor: return 'co2';
      case DeviceType.airQualitySensor: return 'air_quality';
      case DeviceType.moistureSensor: return 'water_drop';
      case DeviceType.motionSensor: return 'motion_sensor';
      case DeviceType.doorSensor: return 'door';
      case DeviceType.windowSensor: return 'window';
      case DeviceType.smokeSensor: return 'smoke_detector';
      case DeviceType.smartLight: return 'lightbulb';
      case DeviceType.smartPlug: return 'outlet';
      case DeviceType.smartSwitch: return 'toggle_on';
      case DeviceType.smartCurtain: return 'curtains';
      case DeviceType.smartLock: return 'lock';
      case DeviceType.smartSpeaker: return 'speaker';
      case DeviceType.camera: return 'videocam';
      case DeviceType.gateway: return 'router';
      case DeviceType.controller: return 'settings_remote';
      case DeviceType.other: return 'devices_other';
      case DeviceType.unknown: return 'help_outline';
    }
  }
  
  /// 判断是否为传感器类型
  bool get isSensor {
    return this == DeviceType.temperatureSensor ||
        this == DeviceType.humiditySensor ||
        this == DeviceType.lightSensor ||
        this == DeviceType.co2Sensor ||
        this == DeviceType.airQualitySensor ||
        this == DeviceType.moistureSensor ||
        this == DeviceType.motionSensor ||
        this == DeviceType.doorSensor ||
        this == DeviceType.windowSensor ||
        this == DeviceType.smokeSensor;
  }
  
  /// 判断是否为控制类型
  bool get isController {
    return this == DeviceType.smartLight ||
        this == DeviceType.smartPlug ||
        this == DeviceType.smartSwitch ||
        this == DeviceType.smartCurtain ||
        this == DeviceType.smartLock ||
        this == DeviceType.smartSpeaker ||
        this == DeviceType.controller;
  }
  
  /// 判断是否为网关或摄像头
  bool get isGateway {
    return this == DeviceType.gateway || this == DeviceType.camera;
  }
} 